<template>
  <div>
    <MainInfo class="" :maininfo="flyInfoMain"/>
    <el-card class="box-card info-color">
      <el-collapse v-model="activeNames" @change="handleChange">
        <el-collapse-item v-for=" (item, index)  in detailList" :title="items[index].title" :name="items[index].name"
                          :key="index">
          <InfoDetail class="row" :item="item"/>

        </el-collapse-item>
      </el-collapse>
    </el-card>


  </div>

</template>

<script>
  import {
    Indicator,
    Toast,
    MessageBox
  } from 'mint-ui'
  import MainInfo from './MainInfo'
  import TimeLine from './TimeLine'
  import Header from './Header'
  import InfoDetail from './InfoDetail'
  import HeaderToLast from './HeaderToLast'
  import HeaderCustom from './HeaderCustom'
  import Global from './Global'
  import axios from 'axios'
  import utils from '../utils'

  export default {
    name: 'DetailInfoPageForGroup',
    // props:['list'],
    components: {HeaderCustom, HeaderToLast, InfoDetail, Header, TimeLine, MainInfo},
    data () {
      return {
        headtitle: '信息详情',
        isReleasePage:true,
        maininfo: {},
        flyInfoMain: {},
        detailList: [],
        activeNames: ['1'],
        items: [],
        params: {},
        url: ''
      }
    },
    methods: {

      delinfo (item,index) {
        console.log('delinfo')
        let that=this
        axios.delete(Global.serverSrc + '/fly/info/detail/one',  {data: item})
          .then(function (res) {
            console.log(res)

            if (res.data.code === 0) {
              Toast({
                message: '表单提交成功',
                position: 'bottom'
              })
              that.detailList.splice(index,1)
            }else{
              Toast({
                message: '表单提交失败',
                position: 'bottom'
              })
            }


            // this.$router.go(-1)
          })
          .catch(function (err) {
            console.log(err)
            Indicator.close()
            Toast({
              message: '表单提交失败',
              position: 'bottom'
            })
          })
      },
      delWholeInfo () {
        this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          console.log('删除')

          axios.post(Global.serverSrc + '/fly/info/create/batch', {
            flyInfoMain: mainData,
            flyInfoDetailList: addList
          })
            .then(function (res) {
              console.log(res)
              Indicator.close()

              Toast({
                message: '表单提交成功',
                position: 'bottom'
              })
              this.$router.go(-1)
            })
            .catch(function (err) {
              console.log(err)
              Indicator.close()
              Toast({
                message: '表单提交失败',
                position: 'bottom'
              })
            })
        }).catch(() => {

        })
      },
      handleChange (val) {
        console.log(val)
      }
    },
    created () {

      document.title='我接收的'
      this.mainId = this.$route.params.mainId
      let queryString = utils.getQueryString('mainId')

      let that=this
      axios({
        method: 'get',
        url: Global.serverSrc + '/userReceive/flyInfo?mainId='+queryString
      }).then(function (resp) {
        console.log(resp.data)
        if (resp.data.code == 0) {
          that.flyInfoMain=resp.data.data.flyInfoMain
          that.detailList=resp.data.data.flyInfoDetailList
          console.log(resp.data)
        }

        for (let i = 0; i < that.detailList.length; i++) {
          var item = {}
          item.name = i + 1 + ''
          item.title = '架次' + (i + 1)
          that.items.push(item)
        }

      }).catch(resp => {
        console.log('请求失败：' + resp.status + ',' + resp.statusText)
      })



    }
  }
</script>

<style scoped>
  .fix-bottom {
    margin: 0 auto;
    display: block;
    width: 98%;
    position: fixed;
    bottom: 0;
  }

  .row {
    text-align: left;
  }

</style>
